<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ page import="com.hzqy.commons.utils.ConstantUtils" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>强切组计划修改页</title>
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/defalut.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/public.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/icon.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/WdatePicker/skin/WdatePicker.css">
<script type="text/javascript" src="../../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript"	src="../../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../../static/js/jquery.validate.js"></script>
<script type="text/javascript" src="../../static/js/index.js"></script>
<script type="text/javascript" src="../../static/js/WdatePicker/WdatePicker.js"></script>
<script type="text/javascript" charset="utf-8" src="../../ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="../../ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" charset="utf-8" src="../../ueditor/lang/zh-cn/zh-cn.js"></script>
	<script type="text/javascript" charset="utf-8" src="../../static/js/Base64.js"></script>
	<script type="text/javascript" charset="utf-8" src="../../static/js/beforeData.js"></script>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<%
	String para =request.getParameter("f_igs_id");
	int f_igs_id = 0;
	if(para != null)
		f_igs_id = Integer.valueOf(para);
	String []nonceObj=ConstantUtils.getNonceObject();
%>
<script type="text/javascript">
var schedulesIndex = 0;
	$(function() {
		var f_igs_id = <%=f_igs_id%>;
		var beforeDataJson={};
		$.ajax({
			url:"../behavior/select_group_schedules.do?f_igs_id="+f_igs_id,
			success:function(data) {
				data = JSON.parse(data);
				$("#f_igs_id").val(data.f_igs_id);
				$("#f_igs_name").val(data.f_igs_name);
				$("#f_igs_orgName").val(data.f_igs_orgName);
				$("#f_igs_orgId").val(data.f_igs_orgId);
				beforeDataJson['f_igs_id']=data.f_igs_id;
				beforeDataJson['f_igs_name']=data.f_igs_name;
				beforeDataJson['f_igs_orgName']=data.f_igs_orgName;
				beforeDataJson['f_igs_orgId']=data.f_igs_orgId;
				beforeDataJson['f_igs_status']=data.f_igs_status;
				$.ajax({
					url:"../behavior/schedules_list.do?f_is_igsId="+f_igs_id,
					success:function(data) {
						data = JSON.parse(data);
						for(var i=0;i<data.length;i++){
							addSchedules();
							$("#f_is_name"+(i+1)).val(data[i].f_is_name);
							$("#f_is_type"+(i+1)).val(data[i].f_is_type);
							$("#f_is_status"+(i+1)).val(data[i].f_is_status);
							$("#f_is_startTime"+(i+1)).val(data[i].f_is_startTime.substring(0,19));
							$("#f_is_endTime"+(i+1)).val(data[i].f_is_endTime.substring(0,19));
							$("#f_is_frequency"+(i+1)).val(data[i].f_is_frequency);
							if(data[i].f_is_frequency>0){
								$("#day"+(i+1)).val(10);
								$('#weekday'+(i+1)).show();
								$("#weekday"+(i+1)).val(data[i].f_is_frequency);
							}
							$("#f_cc_id"+(i+1)).val(data[i].f_is_contentId);
							$("#f_cc_name"+(i+1)).val(data[i].f_is_contentName);
							$("#f_is_viewindex"+(i+1)).val(data[i].f_is_viewindex);
							beforeDataJson['industrySchedulesVoList['+i+"].f_is_name"]=data[i].f_is_name;
							beforeDataJson['industrySchedulesVoList['+i+"].f_is_type"]=data[i].f_is_type;
							beforeDataJson['industrySchedulesVoList['+i+"].f_is_status"]=data[i].f_is_status;
							beforeDataJson['industrySchedulesVoList['+i+"].f_is_startTime"]=data[i].f_is_startTime.substring(0,19);
							beforeDataJson['industrySchedulesVoList['+i+"].f_is_endTime"]=data[i].f_is_endTime.substring(0,19);
							beforeDataJson['industrySchedulesVoList['+i+"].f_is_frequency"]=data[i].f_is_frequency;
							if(data[i].f_is_frequency>0){
								beforeDataJson['day'+(i+1)]=10;
								beforeDataJson['weekday'+(i+1)]=data[i].f_is_frequency;
							} else {
								beforeDataJson['day'+(i+1)]=0;
								beforeDataJson['weekday'+(i+1)]=1;
							}
							beforeDataJson['industrySchedulesVoList['+i+"].f_is_contentId"]=data[i].f_is_contentId;
							beforeDataJson['f_cc_name'+(i+1)]=data[i].f_is_contentName;
							beforeDataJson['industrySchedulesVoList['+i+"].f_is_viewindex"]=data[i].f_is_viewindex;
						}
						beforeData(beforeDataJson, f_igs_id, "", "../../beforeData.do");
					}
				});
			}
		});
		
		$("#contentForm").validate({
			rules: {
				f_igs_name: {
					required: true,
					maxlength: 50
				},
				f_igs_orgName: {
					required: true
				}
				
			},
			messages: {
				f_igs_name: {
					required: "请输入分组名称",
					maxlength: "分组名称不能超过50位"
				},
				f_igs_orgName: {
					required: "请选择客户",
				}
			}
			
		});
		
	});

	function _submitFm() {
		if($("#contentForm").validate().form()) {
		for(var i=0;i<schedulesIndex;i++){
			$("#f_is_frequency"+(i+1)).val($("#day"+(i+1)).val()==0? 0:$("#weekday"+(i+1)).val());
		}
		app_ajax('../behavior/update_group_schedules.do', $("#contentForm").serialize(), function(data) {
			if (data.success) {
				$.ajax({
					url: "../../cache/clear_web_cache.do",
					type: "GET",
					data: {},
					dataType: "json",
					success: function(data) {}
				});
				$.messager.progress('close');
				$.messager.alert('提示', '提交成功！', 'info', function() {
					parent.$('#dlg').dialog('close');
					parent.gotoSearch($('#easyui-treegrid'));
				});
			} else {
				$.messager.alert('提示', data.result, 'info', function() {
					$.messager.progress('close');
				});
			}
		});
	  }
	}
	
	function addSchedules(){
		schedulesIndex++;
		var str = '<div id="schedules_'+schedulesIndex+'"">';
			str += '<fieldset>';
			str += '	<div style="width:100%;text-align:center;font-weight:bold;font-size:18px;">计划'+schedulesIndex+'</div>';
			str += '	<table width="100%" border="0" cellpadding="0" cellspacing="0">';
			str += '		<tbody><tr>';
			str += '			<td align="left" width="30%" ><span class="red">&nbsp;*</span>计划名称：<input id="f_is_name'+schedulesIndex+'" name="industrySchedulesVoList['+(schedulesIndex-1)+'].f_is_name" type="text"></td>';
			str += '			<td align="left" width="30%"><span class="red">*</span>强切选项：';
			str += '				<select id="f_is_status'+schedulesIndex+'" name="industrySchedulesVoList['+(schedulesIndex-1)+'].f_is_status">';
			str += '					<option value="1">开启</option>';
			str += '					<option value="2">关闭</option>';
			str += '				</select>';
			str += '			</td>';
			str += '			<td align="left" width="30%"><span class="red">*</span>强切选项：';
			str += '				<select id="f_is_type'+schedulesIndex+'" name="industrySchedulesVoList['+(schedulesIndex-1)+'].f_is_type">';
			str += '					<option value="1">视频强切</option>';
			str += '					<option value="3">图文强切</option>';
			str += '					<option value="2">频道强切</option>';
			str += '					<option value="4">轮播强切</option>';
			str += '				</select>';
			str += '			</td>';
			str += '			<td align="left" width="10%">';
			str += '				<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:\'icon-remove\', plain:true" onclick="scheduleDelete('+schedulesIndex+')">删除计划</a>';
			str += '			</td>';
			str += '		</tr>';
			str += '		<tr>';
			str += '			<td align="left" width="30%"><span class="red">&nbsp;*</span>开始时间：<input id="f_is_startTime'+schedulesIndex+'" name="industrySchedulesVoList['+(schedulesIndex-1)+'].f_is_startTime" type="text" onClick="WdatePicker({skin:\'default\',dateFmt: \'HH:mm:ss\'})" value="" class="yl_inp yw_name" /></td>';
			str += '			<td align="left" width="30%"><span class="red">*</span>结束时间:<input id="f_is_endTime'+schedulesIndex+'" name="industrySchedulesVoList['+(schedulesIndex-1)+'].f_is_endTime" type="text" onClick="WdatePicker({skin:\'default\',dateFmt: \'HH:mm:ss\'})" value="" class="yl_inp yw_name" /></td>';
			str += '			<td align="left" width="30%">计划频率：';
			str += '				<select id="day'+schedulesIndex+'" name="day'+schedulesIndex+'"  onchange="javascript:showWeek('+schedulesIndex+');">';
			str += '					<option value="0">每天</option>';
			str += '					<option value="10">每周</option>';
			str += '				</select>';
			str += '				<select id="weekday'+schedulesIndex+'" name="weekday'+schedulesIndex+'" style="display:none;">';
			str += '					<option value="1">周一</option>';
			str += '					<option value="2">周二</option>';
			str += '					<option value="3">周三</option>';
			str += '					<option value="4">周四</option>';
			str += '					<option value="5">周五</option>';
			str += '					<option value="6">周六</option>';
			str += '					<option value="7">周日</option>';
			str += '				</select>';
			str += '				<input type="hidden" id="f_is_frequency'+schedulesIndex+'" name="industrySchedulesVoList['+(schedulesIndex-1)+'].f_is_frequency" value="00"/>';;
			str += '			</td>';
			str += '		</tr>';
			str += '		<tr>';
			str += '			<td align="left" colspan="2">';
			str += '				&nbsp;<span class="red">*</span>节目选择：';
			str += '				<input name="f_cc_name'+schedulesIndex+'" id="f_cc_name'+schedulesIndex+'" readonly="readonly" value="" class="yl_inp yw_name" />';
			str += '				<input type="hidden" id="f_cc_id'+schedulesIndex+'" name="industrySchedulesVoList['+(schedulesIndex-1)+'].f_is_contentId" value="0"/>';
			str += '				<a class="easyui-linkbutton" data-options="iconCls:\'icon-ok\'" href="javascript:void(0);" onclick="programSelect('+schedulesIndex+');">选择</a>';
			str += '			</td>';
			str += '			<td align="left" width="30%" >排序值：<input id="f_is_viewindex'+schedulesIndex+'" name="industrySchedulesVoList['+(schedulesIndex-1)+'].f_is_viewindex" type="text"></td>';
			str += '		</tr></tbody>';
			str += '	</table>';
			str += '</fieldset>';
			str += '</div>';
		$("#schedules").append(str);
		$.parser.parse();
	}
	
	function scheduleDelete(index){
		$('#schedules_'+index).remove();
	}

	function orgSelect(){
		openDialog($('#org_list'),'org_update.jsp?idField=f_igs_orgId&nameField=f_igs_orgName');
	}
	
	function programSelect(index){
		openDialog($('#content_list'),'content_update.jsp?index='+index);
	}
	function showWeek(index){
		var val = $('#day'+index).val();
		if(val==0){
			$('#weekday'+index).hide();
		}else{
			$('#weekday'+index).show();
		}
	}
</script>
<style type="text/css">
</style>
</head>

<body class="overfwidth">
	<div class="barnavtop">您所在的位置：分组管理 &gt; 分组新增</div>
	<div id="workspace">
		<!--主体 开始-->
		<div id="container-1">
			<div class="editspace">
				<form id="contentForm" class="cmxform" enctype="multipart/form-data" name="formName">
					<input type="hidden" id="f_igs_id" name="f_igs_id" value="" />
					<input type="hidden" id="f_igs_status" name="f_igs_status" value="1" />
					<input type="hidden" name="stime" value="<%=nonceObj[0]%>"/>
					<input type="hidden" name="sign" value="<%=nonceObj[1]%>"/>
					
					<legend style="text-align: center; margin: 0 auto;">分组新增</legend>
					<a id="switchItemBtn" class="easyui-linkbutton" style="position: fixed; top: 108px; right: 0; background: #D2E0F2; border: 1px solid #95B8E7;" data-options="iconCls:'icon-add'" plain="true" href="javascript:addSchedules();">增加计划</a>
					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="20%" align="right">
										<span class="red">*</span>分组名称:
									</td>
									<td width="30%">
										<input id="f_igs_name" name="f_igs_name" style="width: 150px;" value="" class="yl_inp yw_name" />
										<span id="f_igs_name_tip" class="tip"></span>
									</td>
									<td width="10%" align="right">
										<span class="red">*</span>客户选择:
									</td>
									<td width="30%">
										<input name="f_igs_orgName" id="f_igs_orgName" readonly="readonly"	style="width: 150px;" value="" class="yl_inp yw_name" /> 
										<input type="hidden" id="f_igs_orgId" name="f_igs_orgId"  value="0"/>
										<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0);"
											onclick="orgSelect();">选择</a>
									</td>
								</tr>
							</table>
						</div>
					</fieldset>
					
					<div id="schedules"></div>
					
					<div class="toolbar" style="text-align: center;">
						<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
							href="javascript:void(0);" onclick="_submitFm()">保存</a> <a
							href="javascript:void(0);" data-options="iconCls:'icon-cancel'"
							class="easyui-linkbutton"
							onclick="javascript:parent.$('#dlg').dialog('close')">取消</a>
					</div>
				</form>
			</div>
		</div>
		<!--主体 结束-->
		
		
	</div>
	<div id="org_list" class="easyui-dialog"
		style="width: 800px; height: 500px; padding-top: 0px;"
		data-options="title:'客户选择', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
		<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
	</div>
	<div id="content_list" class="easyui-dialog"
		style="width: 800px; height: 500px; padding-top: 0px;"
		data-options="title:'节目选择', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
		<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
	</div>
	<div id="dlg" class="easyui-dialog"
		style="width: 800px; height: 500px; padding-top: 0px;"
		data-options="title:'企业管理', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
		<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
	</div>
</body>
</html>
